package logic

import (
	"context"
	"user-profile/userProfileRpc/userProfileRpc"

	"user-profile/api/internal/svc"
	"user-profile/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.UpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.UserRpc.UserUpdate(l.ctx, &userProfileRpc.UserUpdateRequest{
		HeadImage: req.HeadImage,
		Name:      req.Name,
		Tel:       req.Tel,
		Birthday:  req.Birthday,
		Sex:       req.Sex,
		Introduce: req.Introduce,
		UserId:    int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil

	}
	return &types.Response{
		Code:    200,
		Message: "用户信息完善成功",
		Data:    update,
	}, nil
}
